package com.tyk.bookstore.front.product.controller;


import com.tyk.bookstore.front.common.core.model.result.R;
import com.tyk.bookstore.front.product.model.query.BookCollectPageQuery;
import com.tyk.bookstore.front.product.model.vo.BookPageVo;
import com.tyk.bookstore.front.product.service.BookService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author tyk
 * @description 收藏管理
 */
@RequestMapping({"api/product/collect"})
@RestController
@Tag(name = "商品管理/收藏管理", description = "书收藏管理")
@Validated
@RequiredArgsConstructor
public class BookCollectController {

    private final BookService bookService;

    @GetMapping({"page"})
    @Operation(summary = "获取收藏列表", description = "获取收藏列表")
    public R<BookPageVo> getPage(
            @Validated @ParameterObject BookCollectPageQuery query
    ) {
        return R.ok(bookService.getCollectPage(query));
    }

    @PostMapping({"{bookId}"})
    @Operation(summary = "收藏/取消收藏书籍", description = "收藏/取消收藏书籍")
    public R<Object> collectOrCancel(
            @Schema(description = "书籍ID") @NotNull @Min(1)
            @PathVariable Long bookId
    ) {
        bookService.collectOrCancel(bookId);
        return R.ok();
    }

}
